package com.example.lixudongdazuoye;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import org.litepal.LitePal;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    private Button signin;
    private Button newUser;
    private ImageView imageView;
    private AnimationDrawable animationDrawable;
    private Button button;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        LitePal.initialize(this);
        signin = (Button) findViewById(R.id.signin);
        newUser = (Button) findViewById(R.id.newUser);
        signin.setOnClickListener(this);
        newUser.setOnClickListener(this);

        imageView = (ImageView) findViewById(R.id.imageView);
        button=(Button)findViewById(R.id.start);
        button.setOnClickListener(this);
        button.performClick();
        setSrc2FrameAnim();
    }
    private void setSrc2FrameAnim() {
        animationDrawable = new AnimationDrawable();
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.tu1), 500);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.tu2), 500);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.tu3), 500);
        animationDrawable.addFrame(
                getResources().getDrawable(R.drawable.tu4), 500);
        animationDrawable.setOneShot(false);
        imageView.setBackground(animationDrawable);

    }
    @Override
    public void onClick(View v) {
        Intent intent;
        if (v.getId() == R.id.signin) {//转到登录界面
            intent = new Intent(MainActivity.this, LoginActivity.class);
            startActivity(intent);
        } else if (v.getId() == R.id.newUser) {//转到注册界面
            intent = new Intent(MainActivity.this, RegistActivity.class);
            startActivity(intent);
        }else if (v.getId() == R.id.start) {//转到注册界面
            if (animationDrawable != null && !animationDrawable.isRunning()) {
                animationDrawable.start();
            }
        }
    }
}